package org.pi.common.gui.clipboard

object Clipboard {

	/** copy a bufferedimage to the clipboard */
	def copyImageToClipboard(image: java.awt.image.BufferedImage): Unit = {
		val c = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
		c.setContents(new org.pi.common.gui.clipboard.ClipImage(image) , null);
	}

	/** copy a matrix as image to clipboard */
	def copyImageToClipboard(image: org.pi.common.matrix.FloatMatrix): Unit = {
		import org.pi.common.vision.io.ImageIO._
		if (image.shape.length==2) // gray
		{
			createBufferedImageFromGrayArray(image, true, 0.0f ,1.0f)
		}
		else if (image.shape.length==3 && image.length(3)==3) // rgb
		{
			createBufferedImageFromRgbArray(image, true, 0.0f ,1.0f)
		}
		else
		{
			throw new Error("unsupported matrix size = "+image.shape.foldLeft("")(_+" "+_))
		}
	}
}
